<?php
/*------------------------------------------------------------------------

# TZ Portfolio Extension

# ------------------------------------------------------------------------

# author    DuongTVTemPlaza

# copyright Copyright (C) 2012 templaza.com. All Rights Reserved.

# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL

# Websites: http://www.templaza.com

# Technical Support:  Forum - http://templaza.com/Forum

-------------------------------------------------------------------------*/
defined('_JEXEC') or die;

require_once JPATH_SITE.'/components/com_tz_portfolio/helpers/route.php';

class modtzteaserslide{
    static function getcontentslide($params){
        $number_inslide = $params ->get('number_inslide');

        $db = JFactory::getDbo();

        $query = $db -> getQuery(true);
        $query ->select(array('content.*,x_content.*'));
        $query ->from('#__content as content,#__tz_portfolio_xref_content AS x_content');
        $query ->where('content.id = x_content.contentid');

        $cate_array = $params->get('categories');
        $string="";
        for($j=0;$j<count($cate_array);$j++){
            if($j == (count($cate_array))-1){
                $string = $string. $cate_array[$j];
            }
            else{
                $string = $string. $cate_array[$j].',';
            }
        }
        $query ->where('content.catid in ('.$string.')');

        $type_array = $params->get('type_slide');

        $string2="";
        for($k=0;$k<count($type_array);$k++){
            if($k == (count($type_array))-1){
                $string2 = $string2."'".$type_array[$k]."'";
            }
            else{
                $string2 = $string2."'".$type_array[$k]."'".',';
            }
        }
        $query ->where('x_content.type in ('.$string2.')');

        $query ->order('content.id DESC');
        //var_dump($query -> dump()); die();

        $db -> setQuery($query,0,$number_inslide);

        if($rows = $db -> loadObjectList()){
            for($i = 0; $i < count($rows); $i++){
                $rows[$i] ->link   =  JRoute::_(TZ_PortfolioHelperRoute::getArticleRoute($rows[$i] -> contentid.':'
                .$rows[$i] ->alias, $rows[$i] -> catid));
            }
            return $rows;
        }
        return false;
    }
}